package com.highgain.displacementtrend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.highgain.displacementtrend.entity.AlarmPara;
import com.highgain.displacementtrend.entity.Result;
import com.highgain.displacementtrend.mapper.AlarmParaMapper;
import com.highgain.displacementtrend.service.AlarmParaService;
import org.springframework.stereotype.Service;

/**
 * @author zhanglifeng
 * @date 2021/04/19 10:57
 **/
@Service
public class AlarmParaServiceImpl extends ServiceImpl<AlarmParaMapper, AlarmPara> implements AlarmParaService {
    @Override
    public Result getAlarmPara(AlarmPara alarmPara) {
        AlarmPara ap = baseMapper.selectOne(
                new QueryWrapper<AlarmPara>()
                        .eq("deviceId", alarmPara.getDeviceId())
                        .eq("alarmTypeId", alarmPara.getAlarmTypeId()));
        return Result.ok("").data(ap);
    }

    @Override
    public Result saveAlarmPara(AlarmPara alarmPara) {
        if(alarmPara.getId() != null){
            return 1 == baseMapper.updateAlarmPara(alarmPara) ? Result.ok("更新成功！") : Result.error("更新失败！");
        }else{
            return 1 == baseMapper.saveAlarmPara(alarmPara) ? Result.ok("保存成功！") : Result.error("保存失败！");
        }
    }
}
